import time
import pytest
import yaml
from selenium import webdriver
import logging

class BasePage:

    def __init__(self, driver=None):
        logging.info("进入网址")

        if driver is None:
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(5)
            self.driver.maximize_window()
            self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")

            cookies = yaml.safe_load(open("../data/cookie.yaml", 'r'))
            logging.info("传递cookie")

            for cookie in cookies:
                self.driver.add_cookie(cookie)
            time.sleep(10)
            self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
        else:
            self.driver = driver

    def do_click(self, by, locator):
        logging.info("点击")
        return self.driver.find_element(by, locator).click() # 方法记得return

    def do_send_keys(self, by, locator, value):
        logging.info("写数据")
        return self.driver.find_element(by, locator).send_keys(value) # 方法记得return

    def finds(self, by, locator):
        return self.driver.find_elements(by, locator)